#pragma once
#include <d3d9.h>
#include <d3dx9.h>

#include "Texture.h"
#include "TextureManager.h"

class Sprite {
protected: 
	Texture *_texture;
	LPD3DXSPRITE _SpriteHandler;

	int _Index, _counter, _delay;								// Current sprite index
	int _IndexStart, _IndexEnd;
	bool _repeat;
	bool _isActive, _endOfSheet;

	void _getViewPos3(D3DXVECTOR3*, D3DXMATRIX*);
	D3DXVECTOR4 viewPos4;
	D3DXVECTOR3 viewPos3;

	RECT srect;

	void _Inititialize(LPD3DXSPRITE SpriteHandler, int fileName, bool repeat);
public: 
	Sprite::Sprite(LPD3DXSPRITE SpriteHandler, int fileName, bool repeat);
	Sprite::Sprite(LPD3DXSPRITE SpriteHandler, int fileName, bool repeat, int framerate);
	Sprite::Sprite(LPD3DXSPRITE SpriteHandler, int fileName);
	void Next();
	void setToEnd();
	void setToStart();
	void Reset();
	void destroy();
	void setStartEnd(int start, int end);
	void active();
	bool endOfSheet();
	void setDelay(int delay);
	void setNoneEnd();
	void setToOver();
	void setIndex(int index);
	int getStartIndex();
	int getDelay();
	// Render current sprite at location (X,Y) at the target surface
	void Render(double X, double Y);	
	void RenderNonTransform(double X, double Y);
	void Render(LPDIRECT3DSURFACE9 Target, double X, double Y);
	void Render(LPDIRECT3DSURFACE9 Target, double X, double Y, int alpha);
	void Render(LPDIRECT3DSURFACE9 Target, D3DXMATRIX* matrix, double X, double Y);	
	int currentIndex();

	void setIndexEnd(int indexEnd);
	~Sprite();
};